<?
require_once('setup.inc.php');
if(!checkQualified("1000")) {
	print "You are not allowed to perform this action! (You=" . $_SESSION[permission] . " : Req'd=1000)";
	die();
}
class PrintSeniorityList {
	var $groupid;
	var $groupDate;
	var $totalResults;
	
	function showSeniorityList(){
		$listData = $this->getListData();
		$totalRows = ceil($this->totalResults / 2);
		for ($i = 1; $i<=$totalRows; $i++){
			if ($i == $totalRows || ($i / 2) == $totalRows) $class = "dataBottom";
			else $class = "data";
			echo "<tr>\n";
			echo "<td class=\"" . $class . "\" align=\"center\">" . $i . "</td>\n";
			echo "<td class=\"" . $class . "\" align=\"center\">" . $listData[$i]['points'] . "</td>\n";
			echo "<td class=\"" . $class . "\">" . $listData[$i]['name'] . "</td>\n";
			echo "<td class=\"" . $class . "\" align=\"center\" style=\"border-left: 2px solid #000000\">" . $listData[$i]['prevrank'] . "</td>\n";
			if (!empty($listData[$i+$totalRows])){
				echo "<td class=\"" . $class . "\" align=\"center\" style=\"border-left: 2px solid #000000\">" . ($i + $totalRows) . "</td>\n";
				echo "<td class=\"" . $class . "\" align=\"center\">" . $listData[$i + $totalRows]['points'] . "</td>\n";
				echo "<td class=\"" . $class . "\">" . $listData[$i + $totalRows]['name'] . "</td>\n";
				echo "<td class=\"" . $class . "\" align=\"center\" style=\"border-left: 2px solid #000000\">" . $listData[$i + $totalRows]['prevrank'] . "</td>\n";
			} else {
				echo "<td class=\"" . $class . "\" align=\"center\" style=\"border-left: 2px solid #000000\">&nbsp;</td>";
				echo "<td class=\"" . $class . "\" align=\"center\">&nbsp;</td>";
				echo "<td class=\"" . $class . "\">&nbsp;</td>";
				echo "<td class=\"" . $class . "\" align=\"center\" style=\"border-left: 2px solid #000000\">&nbsp;</td>";
			}
			echo "</tr>\n";
		}
	}
	
	function checkListID($id){
		$query = "SELECT group_id, date_format(timestamp, '%c/%e/%y') AS timestamp FROM t_seniority_group WHERE group_id = " . quote_smart($id);
		$result = mysql_query($query);
		if (mysql_num_rows($result) == 1) {
			$this->groupid = $id;
			$this->groupDate = mysql_result($result, 0, timestamp);
			return true;
		}
		else return false;
	}
	
	function getListData(){
		$query = "SELECT t_drivers.firstname, t_drivers.lastname, t_seniority_list.points, t_seniority_list.rank, t_seniority_list.prev_rank FROM t_seniority_list JOIN t_drivers ON t_seniority_list.driver_id = t_drivers.driver_id WHERE t_seniority_list.group_id = '" . $this->groupid . "' ORDER BY t_seniority_list.rank ASC";
		$result = mysql_query($query);
		$this->totalResults = mysql_num_rows($result);
		while ($data = mysql_fetch_array($result)){
			$driverName = $data['lastname'] . ", " . $data['firstname'];
			$driverRank = $data['rank'];
			$driverPoints = $data['points'];
			if ($data['prev_rank'] != 0) $driverPrevRank = $data['prev_rank'];
			else $driverPrevRank = "--";
			$listData[$driverRank]['name'] = $driverName;
			$listData[$driverRank]['points'] = $driverPoints;
			$listData[$driverRank]['prevrank'] = $driverPrevRank;
		}
		return $listData;
	}
	
	function getListDate() { return $this->groupDate; }
}

$list = new PrintSeniorityList();
$list->checkListID($_GET['listid']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Shuttle Seniority List - As of <? echo $list->getListDate(); ?></title>
<style type="text/css">
.header {
	font-size: 18px;
	font-weight: bold;
	color: #000066;
	vertical-align: middle;
	text-align: right;
}

.innertable {
	width: 100%;
	border: 2px solid #000000;
}

.greybg {
	background-color: #999999;
	height: 9px;
}

.subHeader {
	border-top: 2px solid #000000;
	border-bottom: 2px solid #000000;
	font-size: 24px;
	padding: 6px;
}

.data {
	border-bottom: 1px dotted #000000;
	padding: 1px;
}

.dataBottom {
	padding: 1px;
}

table {
	font-family: Geneva, Arial, Helvetica, sans-serif;
}

.dataTable {
	font-size: 13px;
}

.theader {
	border-top: 2px solid #000000;
	border-bottom: 2px solid #000000;
	font-weight: bold;
	padding: 3px;
}

.spacercol {
	height: 5px;
}
</style>
</head>
<body>
<table width="700" align="center">
	<tr>
		<td><img src="images/senioritylistlogo.jpg" width="197" height="56" alt="University Of Connecticut" /></td>
		<td class="header">Transportation Services</td>
	</tr>
	<tr>
		<td colspan="2" class="spacercol"></td>
	</tr>
	<tr>
		<td colspan="2">
			<table class="innertable" cellpadding="0" cellspacing="0">
				<tr>
					<td colspan="2"><img src="images/senioritylistbg.gif" width="700" height="9" alt="" /></td>
				</tr>
				<tr>
					<td class="subHeader">Shuttle Seniority List</td>
					<td align="right" class="subHeader">As of <? echo $list->getListDate(); ?></td>
				</tr>
				<tr>
					<td colspan="2" ><img src="images/senioritylistbg.gif" width="700" height="9" alt="" /></td>
				</tr>
				<tr>
					<td colspan="2">
						<table width="100%" cellpadding="0" cellspacing="0" class="dataTable">
							<tr>
								<td class="theader" align="center">Rank</td>
								<td class="theader" align="center">Points</td>
								<td class="theader">Name</td>
								<td class="theader" style="border-left: 2px solid #000000" align="center">Prev.Rank.</td>
								<td class="theader" style="border-left: 2px solid #000000" align="center">Rank</td>
								<td class="theader" align="center">Points</td>
								<td class="theader">Name</td>
								<td class="theader" style="border-left: 2px solid #000000" align="center">Prev.Rank.</td>
							</tr>
<?
$list->showSeniorityList();
?>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>